/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package be.esi.athanfree.localisation.xml;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.jdom.Element;
import org.jdom.Text;
import org.jdom.input.SAXBuilder;

/**
 *
 * @author Yacine
 */
public class LocalisationFromXml {

    static org.jdom.Document document;
    static Element racine;
    //TODO à continuer
    public static List<City> getCityFromCountry(String country) {
        List<City> cities = new ArrayList<City>();
        
        SAXBuilder sxb = new SAXBuilder();
        try {
            document = sxb.build(new File(".\\src\\be\\esi\\athanfree\\localisation\\xml\\country\\"+country+".xml"));
        } catch (Exception e) {
            System.out.println(e);
        }
        racine = document.getRootElement();
        List listeVilles = racine.getChildren();
        Iterator i = listeVilles.iterator();
        while (i.hasNext()) {
            Element courant = (Element) i.next();
            //cities.add(courant.getAttribute("name").getValue());
        }


        return cities;
    }

    public static List<String> getAllCountries() {

        List<String> countries = new ArrayList<String>();

        SAXBuilder sxb = new SAXBuilder();
        try {
            document = sxb.build(new File(".\\src\\be\\esi\\athanfree\\localisation\\xml\\countries.xml"));
        } catch (Exception e) {
            System.out.println(e);
        }
        racine = document.getRootElement();
        List listeVilles = racine.getChildren();
        Iterator i = listeVilles.iterator();
        while (i.hasNext()) {
            Element courant = (Element) i.next();
            countries.add(courant.getAttribute("name").getValue());
        }
        return countries;
    }
}
